package cn.wolfcode.wms.page;

import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class PageResult {
    private int currentPage;
    private int pageSize;
    private int totalPage;
    private int totalCount;
    private int prevPage;
    private int nextPage;
    private List<?> list;

    public PageResult(List<?> list,int totalCount, int currentPage, int pageSize) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.list = list;
        this.totalPage = this.totalCount % this.pageSize ==0 ? this.totalCount/this.pageSize : this.totalCount/this.pageSize + 1;
        this.prevPage = this.currentPage -1 >= 1 ? this.currentPage - 1 : 1;
        this.nextPage = this.currentPage + 1 <= totalPage ? this.currentPage + 1 : this.totalPage;
    }

    public static PageResult empty(int pageSize){
        return new PageResult(Collections.emptyList(),0,1,pageSize);
    }
}
